package com.lwl.service.impl.mht;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwl.entity.MyPage;
import com.lwl.entity.mht.TMhtCallback;
import com.lwl.entity.Tuser;
import com.lwl.service.mht.TMhtCallbackService;
import com.lwl.dao.mht.TMhtCallbackMapper;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * (TMhtCallback)表服务实现类
 * @author Lei
 * @since 2022-11-02 17:28:00
 */
@Service
public class TMhtCallbackServiceImpl implements TMhtCallbackService {
   @Autowired
   private TMhtCallbackMapper tMhtCallbackDao;

   @Override
   public PageInfo queryAll(MyPage myPage, TMhtCallback tMhtCallback) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<TMhtCallback> tMhtCallbackList = tMhtCallbackDao.selectAll();
      PageInfo pageInfo = new PageInfo<>(tMhtCallbackList);
      return pageInfo;
   }

   @Override
   public int insertCallback(TMhtCallback tMhtCallback, HttpSession session) {
      int insert = -1;
//      判断是否有id，来确定是添加还是修改回访记录
      if (tMhtCallback.getId()==null){
         tMhtCallback.setCreatetime(new Date());
         insert = tMhtCallbackDao.insert(tMhtCallback);
      }else {
         tMhtCallback.setUpdatetime(new Date());
         Tuser user = (Tuser)session.getAttribute("user");
         String username = user.getUsername();
         tMhtCallback.setUpdateby(username);
         insert = tMhtCallbackDao.updateByPrimaryKeySelective(tMhtCallback);
      }
      return insert;
   }


}
